#include  "memoryManager.h"

MemoryManager* MemoryManager::getInstance( )
{
    if ( NULL == instance)
    {
        instance = new MemoryManager( );
    }
    return instance;
}

MemoryManager::MemoryManager( )
    :developersAllocations(0), testersAllocations( 0)
{
    traceFile.open( "memory.txt", std::ios::trunc | std::ios::in);
}

MemoryManager::~MemoryManager( )
{
    traceFile.close( );
}

void MemoryManager::allocateForDeveloper( int size)
{
    developersAllocations += size;
    traceFile << "allocated new - " << size 
              << " bytes for class DeveloperEmployee"
              << std::endl
              << "allocated total - " << developersAllocations
              << " bytes for class DeveloperEmployee" << std::endl;
}

void MemoryManager::allocateForTester( int size)
{
    testersAllocations += size;
    traceFile << "allocated new - " << size 
              << " bytes for class TesterEmployee"
              << std::endl
              << "allocated total - " << developersAllocations
              << " bytes for class TesterEmployee" << std::endl;
}

void MemoryManager::releaseForDeveloper( int size)
{
    developersAllocations-=size;
    traceFile << "freed new - " << size 
              << " bytes for class DeveloperEmployee"
              << std::endl
              << "allocated total - " << developersAllocations
              << " bytes for class DeveloperEmployee" << std::endl;
}

void MemoryManager::releaseForTester( int size)
{
    testersAllocations-=size;
    traceFile << "freed new - " << size 
              << " bytes for class TesterEmployee"
              << std::endl
              << "allocated total - " << developersAllocations
              << " bytes for class TesterEmployee" << std::endl;
}
